package com.springmvc02.demo.controller;

import com.springmvc02.demo.pojo.ResultVO;
import com.springmvc02.demo.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("/test")
@ResponseBody
public class TestController {


    //请求行请求
    @RequestMapping("/test01")
    public ResultVO<?> test01(@RequestParam("name") String userName, @RequestParam("age") Integer userAge) {
        Map<String,String> map = new HashMap<>();
        map.put("name",userName);
        map.put("age",userAge.toString());
        return new ResultVO<>(200, "请求成功", map);
    }
    //请求头请求
    @RequestMapping("/test02")
    public ResultVO<?> test02(@RequestHeader("token") String token){
        Map<String,String> map = new HashMap<>();
        map.put("token",token);
        return new ResultVO<>(200, "请求成功", map);
    }
    //请求体请求
    @RequestMapping("/test03")
    public ResultVO<?> test03(@RequestBody User user){
        Map<String,String> map = new HashMap<>();
        map.put("name",user.getName());
        map.put("age",user.getAge().toString());
        map.put("sex",user.getSex());
        map.put("address",user.getAddress());
        map.put("email",user.getEmail());
        map.put("phone",user.getPhone());
        return new ResultVO<>(200, "请求成功", map);
    }

    @RequestMapping("/test04")
    public ResultVO<?> test04(@RequestParam("name") String userName, @RequestParam("age") Integer userAge,
                              @RequestHeader String token,@RequestBody User user){
        Map<String,String> map = new HashMap<>();
        map.put("name",userName);
        map.put("age",userAge.toString());
        map.put("token",token);
        map.put("userName",user.getName());
        map.put("userAge",user.getAge().toString());
        map.put("userSex",user.getSex());
        map.put("userAddress",user.getAddress());
        map.put("userEmail",user.getEmail());
        map.put("userPhone",user.getPhone());
        return new ResultVO<>(200, "请求成功", map);
    }


}
